<?php require_once('Connections/learnConn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO buku_tamu (id_buku_tamu, nama_tamu, email_tamu, pesan_tamu, stat) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id_buku_tamu'], "int"),
                       GetSQLValueString($_POST['nama_tamu'], "text"),
                       GetSQLValueString($_POST['email_tamu'], "text"),
                       GetSQLValueString($_POST['pesan_tamu'], "text"),
                       GetSQLValueString(0, "int"));

  mysql_select_db($database_learnConn, $learnConn);
  $Result1 = mysql_query($insertSQL, $learnConn) or die(mysql_error());

  $insertGoTo = "buku_tamu.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_learnConn, $learnConn);
$query_bukutamu = "SELECT * FROM buku_tamu WHERE stat = 1";
$bukutamu = mysql_query($query_bukutamu, $learnConn) or die(mysql_error());
$row_bukutamu = mysql_fetch_assoc($bukutamu);
$totalRows_bukutamu = mysql_num_rows($bukutamu);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hubungi Kami</title>
<link href="style/style.css" type="text/css" rel="stylesheet" />
<link href="style/pro_drop_1.css" type="text/css" rel="stylesheet"/>
<script src="style/stuHover.js" type="text/javascript"></script>
</head>

<body><center>

<table width="900" bgcolor="#FFFFFF">
	<?php
	include "topmenu.php";
	?>
    <tr>
   	  <td id="menu">
        <?php
		include "menu_kiri.php";
		?>
        </td>
		
    	<td id="konten"><form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
    	  <table align="center">
    	    <tr valign="baseline">
    	      <td nowrap="nowrap" align="right"></td>
    	      <td>Hubungi Kami<br>
			Hubungi kami secara online dengan mengisi form dibawah ini:
			<br>
			<br>
			<br>
			</td>
  	      </tr>
		  <tr valign="baseline">
    	      <td nowrap="nowrap" align="right">Nama:</td>
    	      <td><input name="nama_tamu" type="text" value="" size="32" maxlength="18" /></td>
  	      </tr>
    	    <tr valign="baseline">
    	      <td nowrap="nowrap" align="right">Email:</td>
    	      <td><input type="text" name="email_tamu" value="" size="32" /></td>
  	      </tr>
    	    <tr valign="baseline">
    	      <td nowrap="nowrap" align="right" valign="top">Pesan:</td>
    	      <td><textarea name="pesan_tamu" cols="50" rows="5"></textarea></td>
  	      </tr>
    	    <tr valign="baseline">
    	      <td nowrap="nowrap" align="right">&nbsp;</td>
    	      <td><input type="submit" value="Kirim" /></td>
  	      </tr>
  	    </table>
    	  <input type="hidden" name="id_buku_tamu" value="" />
    	  <input type="hidden" name="MM_insert" value="form1" />
  	  </form><br /><br />
          <table width="100%" border="0">
		  <!--
            <tr bgcolor="#258cf5">
              <td width="100">Nama</td>
              <td>Pesan</td>
            </tr>
			-->
            <?php do { ?>
            <tr>
              <td><?php //echo $row_bukutamu['nama_tamu']; ?></td>
              <td><?php //echo $row_bukutamu['pesan_tamu']; ?></td>
            </tr>
              <?php } while ($row_bukutamu = mysql_fetch_assoc($bukutamu)); ?>
          </table>
        <p>&nbsp;</p></td>
    </tr>
    <tr>
    	<td colspan="2" id="footer">Copyright 2012</td>
    </tr>
    
</table></center>
</body>
</html>
<?php
mysql_free_result($bukutamu);
?>
